package com.moyou.weichat.utils;

import android.app.Activity;
import android.content.Context;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by Administrator on 2017/11/7 0007.
 * sj: 2017年11月7日14:23:45
 * name: ts
 * 用途： 如键盘监听
 */

public class InputUtils {
    private static InputMethodManager inputMethodManager;
    public static  InputUtils inputUtils;

    public static  InputUtils getInputUtils(){
        return inputUtils == null ? inputUtils = new InputUtils() : inputUtils;
    }

    //关闭软键盘
    public void hideSoftKeyboard(Activity activity) {
        inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (activity.getCurrentFocus() != null)
                inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
